// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'
import Vuex from 'vuex'
import App from './App'
import router from './router'
import ElementUI from 'element-ui'
import 'element-ui/lib/theme-chalk/index.css'

import mavonEditor from 'mavon-editor'
import 'mavon-editor/dist/css/index.css'
import Notice from '../src/components/KNotice/notice'

Vue.use(Vuex);

let store =new Vuex.Store({
  state:{
    num:30
  },
  getters:{
    getNum(state){
      return state.num
    }
  },
  mutations:{
    addNum(state,payload){
      state.num+=payload.num
    }
  }
})

Vue.use(ElementUI)
// use
Vue.use(mavonEditor)

Vue.prototype.$Notice=Notice

Vue.config.productionTip = false
Vue.prototype.$dispatch=function(eventName,data){
  let parent =this.$parent;
  while(parent){
    parent.$emit(eventName,data);
    parent=parent.$parent;
  }
}
Vue.prototype.$boardcast=function(eventName,data){
  boardcast.call(this,eventName,data)
}
function boardcast(eventName,data){
  this.$children.forEach(child=>{
    child.$emit(eventName,data)
    if(child.$children.length){
      boardcast.call(child,eventName,data)
    }
  })
}

class Bus{
  constructor(){
    this.callbacks={}
  }
  $on(name,fn){
    this.callbacks[name]=this.callbacks[name]||[];
    this.callbacks[name].push(fn);
  }
  $emit(name,args){
    if(this.callbacks[name]){
      this.callbacks[name].forEach(cb=>cb(args))
    }
  }
}
Vue.prototype.$bus=new Bus();
//Vue.prototype.$bus=new Vue();

/* eslint-disable no-new */
new Vue({
  el: '#app',
  router,
  store,
  components: { App },
  template: '<App/>'
})
